<div class="col mb-4">
  <div class="card preview-card <%= (file === @model.preview_file) ? "border-primary" : "" %>">
    <% if file.is_image? %>
      <%= content_tag :div, nil, class: "card-img-top card-img-top-background", style: "background-image: url(#{model_model_file_path(@model, file, format: file.extension)})" %>
      <%= image_tag model_model_file_path(@model, file, format: file.extension), class: "card-img-top image-preview", alt: file.name %>
    <% elsif file.is_renderable? %>
      <div class="card-img-top">
        <%= Renderer(file: file) %>
      </div>
    <% else %>
      <%= content_tag :div, nil, class: "card-img-top", style: "aspect-ratio: 1" do %>
        <svg height="100%" width="100%" viewBox="0 0 100 100">
          <path stroke="black" stroke-linecap="round" stroke-width="0.5" fill="white" d="
            M60,15
            h-30
            q-5,0 -5,5
            v65
            q0,5 5,5
            h40
            q5,0 5,-5
            v-55
            L60,15
          " />
          <path stroke="black" stroke-linecap="round" stroke-width="0.5" fill="transparent" d="
            M60,15
            v10
            q0,5 5,5
            h10
          " />
          <text x="50%" y="80%" fill="black" dominant-baseline="middle" text-anchor="middle" style="font-size: 8px"><%= file.extension&.upcase %></text>
        </svg>
      <% end %>
    <% end %>
    <div class="card-body">
      <div class="card-title">
        <%= file.name %>
      </div>
      <div class="card-text">
        <% if file.caption %>
          <p><%= sanitize file.caption %></p>
        <% end %>
        <small><code><%= sanitize file.filename %></code></small>
      </div>
      <div class="row">
        <div class="col">
          <%= link_to t(".open_button.text"), model_model_file_path(@model, file), {class: "btn btn-primary", "aria-label": translate(".open_button.label", name: file.name)} %>
          <%= link_to Icon(icon: "cloud-download-fill", label: t("general.download")), model_model_file_path(@model, file, file.extension&.to_sym, download: "true"), {class: "btn btn-secondary", download: "download"} %>
          <% if file.presupported || file.presupported_version %>
            <%= Icon icon: "bar-chart-line-fill", label: ModelFile.human_attribute_name(:presupported) %>
          <% end %>
          <%= problem_icon_tag(file.problems) if policy(Problem).show? %>
        </div>
        <div class="col col-auto">
          <div class="float-end">
            <%= BurgerMenu(direction: :up) do %>
              <%= slicer_links(file) if file.is_3d_model? %>
              <%= DropdownDivider() %>
              <% if file.presupported_version %>
                <%= DropdownHeader text: t(".presupported") %>
                <%= link_to t("general.download"), model_model_file_path(@model, file.presupported_version, file.presupported_version.extension&.to_sym, download: "true"), {class: "dropdown-item", download: "download"} %>
                <%= slicer_links(file.presupported_version) if file.presupported_version.is_3d_model? %>
                <%= DropdownDivider() %>
              <% end %>
              <%= DropdownItem icon: "pencil-fill", label: t(".edit"), path: edit_model_model_file_path(@model, file) if policy(file).edit? %>
              <%= DropdownItem icon: "image", label: t(".set_as_preview"), path: model_path(@model, "model[preview_file_id]": file.id), method: :patch if policy(@model).edit? && file.is_renderable? || file.is_image? %>
              <%= DropdownItem icon: "trash", label: t(".delete"), path: model_model_file_path(@model, file), method: :delete, confirm: translate("model_files.destroy.confirm") if policy(file).destroy? %>
            <% end %>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
